package cn.xiaolang.thread.lock;

/**
 * 不可重入锁示例:
 * 当前线程执行某个方法的时候获取到锁,那么再次在方法中获取锁时,就会被阻塞;IllegalMonitorStateException
 *
 * @author fuhw/DeanKano
 * @date 2019-01-08
 */
public class MyNonReentrantLock {

	private boolean isLocked = false;

	public void lock() throws InterruptedException {
		while (isLocked) {
			wait();
		}
		isLocked = true;
	}

	public void unlock() {
		isLocked = false;
		notify();
	}
	
}
